package com.swss.g.base;

import java.io.Serializable;
import java.util.List;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projection;

import com.swss.util.Pagination;

public interface BaseDAO<T extends Serializable> {

	// 按id查询
	public T get(Serializable id) throws Exception;

	// 保存一条
	public T save(T entity) throws Exception;
	
	public void saveAll(List<T> list) throws Exception;

	// 更新
	public T update(T entity) throws Exception;

	// 保存或更新
	public T saveOrUpdate(T entity) throws Exception;

	public void saveOrUpdateAll(List<T> list) throws Exception;

	// 删除
	public void delete(T entity) throws Exception;

	// 删除多条
	public void deleteAll(List<T> entities) throws Exception;

	// 按hql查询
	@SuppressWarnings("unchecked")
	public List<T> findByHql(String hql, Pagination pagination)
			throws Exception;

	public List<T> findByHql(String hql) throws Exception;

	
	public T findOneByHql(String hql) throws Exception;

	// 按example查询
	@SuppressWarnings("unchecked")
	public List<T> findByExample(T example, Pagination pagination)
			throws Exception;
	
	public T findOneByExample(T example) throws Exception;


	@SuppressWarnings("unchecked")
	public Pagination<T> findByCriteria(Pagination pagination,
			List<Criterion> criterions, Projection projection,
			List<Order> orders) throws Exception;

	// 查询所有 -分页
	@SuppressWarnings("unchecked")
	public List<T> findAll(Pagination pagination) throws Exception;
	
	

	// 查询条数
	public int findCount() throws Exception;
	public int findCount(String hql) throws Exception;
	// 资产数量和金额  astType G_MAIN=a,G_CHANGEMAIN= chage
	public Long  findAstCount(String hql,String astType) throws Exception;
	public Double findAstAmount(String hql,String astType) throws Exception;
}
